class Solution {
public:
    int triangleNumber(vector<int>& nums)
    {
        int n = nums.size(), count = 0;
        sort(nums.begin(), nums.end());
        for (int i = 0; i < n; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                for (int z = j + 1; z < n; z++)
                {
                    if (nums[i] + nums[j] > nums[z])
                        count++;
                }
            }
        }
        return count;
    }
};